package com.example.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.example.adapter.MyAdapterchecked.Info;
import com.example.juyixia.R;
import com.exanple.data.ChatMsgEntity;
import com.exanple.data.Messageinfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class MessageAdapter extends BaseAdapter {
	private List<Messageinfo> data;
    private LayoutInflater layoutInflater;
    private Context context;
    public MessageAdapter(Context context, List<Messageinfo> list) {
        //传入的data，就是我们要在listview中显示的信息
            this.context = context;
            this.data = list;
            this.layoutInflater = LayoutInflater.from(context);
            
        }
    public class Info {
        public ImageView headimage;
        public TextView username;
        public TextView usercontent;
       public TextView rectime;
       public TextView publickey;
       public TextView ip;
    }
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		 Info info = new Info();
	        convertView = layoutInflater.inflate(R.layout.message_item, null);
	        info.headimage = (ImageView) convertView.findViewById(R.id.message_tou_xiang);
	        info.username = (TextView) convertView
	                .findViewById(R.id.message_name);
	        info.usercontent = (TextView) convertView
	                .findViewById(R.id.thismessage_content);
	        info.rectime=(TextView) convertView
	                .findViewById(R.id.message_time);
             info.publickey=(TextView) convertView
             .findViewById(R.id.messpublickey);
             info.ip=(TextView) convertView
                     .findViewById(R.id.messtoip);
             TextView delete=(TextView) convertView
                     .findViewById(R.id.tv_delete);
             
//             delete.setOnClickListener(new OnClickListener() {
//
//				@Override
//				public void onClick(View v) {
//					// TODO Auto-generated method stub
//					data.remove(position);
//					new MessageAdapter(context, data).notifyDataSetChanged();
//				}
//				
//				
//			});
	        //设置数据
	        info.headimage.setImageResource(R.drawable.default_useravatar);
	        info.username.setText((String) data.get(position).getSendname());
	        info.usercontent.setText((String) data.get(position).getMesscontent());
	        info.rectime.setText((String) data.get(position).getSendtime());
	        info.publickey.setText((String) data.get(position).getPublickey());
	        info.ip.setText((String) data.get(position).getIp());
	        return convertView;
	}

}
